package funcs

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"os"
)

func If(condition bool, trueVal, falseVal interface{}) interface{} {
	if condition {
		return trueVal
	}
	return falseVal
}

func CheckFileIsExist(filename string) bool {
	var exist = true
	if _, err := os.Stat(filename); os.IsNotExist(err) {
		exist = false
	}
	return exist
}

func RootPath() string {
	var rootPath, _ = os.Getwd()
	return rootPath + "/"
}

func Md5V(str string) string {
	h := md5.New()
	h.Write([]byte(str))
	return hex.EncodeToString(h.Sum(nil))
}

func CheckErr(err error) {
	if err != nil {
		panic(err)
	}
}

func CheckRunnable(err error, runnable *bool) {
	if err != nil {
		fmt.Println("CheckRunnable err:", err.Error())
		*runnable = false
	}
}
